package com.brightworks.scripthelper.analyzers
{
    import com.brightworks.scripthelper.constants.LineTypeConstants;
    import com.brightworks.util.Log;
    import com.brightworks.util.Utils_String;

    public class LineTypeAnalyzer_Chunk_TargetLanguage_Romanized extends LineTypeAnalyzer
    {
        private static const PINYIN_LETTERS_WITH_TONE_MARKS:Array = ["ā","á","ǎ","à","ē","é","ě","è","ī","í","ǐ","ì","ō","ó","ǒ","ò","ū","ú","ǔ","ù","ǖ","ǘ","ǚ","ǜ","ü"];

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Getters & Setters
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public static function get lineTypeDescription():String
        {
            return LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE__ROMANIZED;
        }

        public static function get lineTypeId():String
        {
            return LineTypeConstants.LINE_TYPE_ID__CHUNK__TARGET_LANGUAGE__ROMANIZED;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Public Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public function LineTypeAnalyzer_Chunk_TargetLanguage_Romanized()
        {
            super();
            bIsChunkLine = true;
        }

        override public function getProblemReports():Array
        {
            var problemList:Array = [];
            /*if (getToneMarkCharString(lineText).length > 0)
            {
                problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE__ROMANIZED + ". These lines should use numerals to indicate tones, not letters with tone marks. But this line contains these letters: " + getToneMarkCharString(lineText));
            }
            else
            {
                var numericCharCount:int = Utils_String.getNumericCharacterCount(lineText);
                // The -4 is in case it is a short line ending in ",..."
                var ratio:Number = numericCharCount/(lineText.length - 4);
                if (!((ratio > .1) || (lineText.length < 10)))
                    problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE__ROMANIZED + ", and should contain some numeric characters. This line only contains " + numericCharCount + " numeric characters out of a total of " + lineText.length + " characters in this line.");
            }*/
            if (lineText.indexOf("…") != -1)
                problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE__ROMANIZED + ". If these lines contain an ellipsis it should be made up of periods (...), rather than being a Chinese ellipsis character (…). This line contains a Chinese ellipsis character.");
            if (lineText.indexOf("...") != -1)
            {
                var bProblem:Boolean = false;
                if (lineText.indexOf("...") == (lineText.length - 3))
                {
                    if (lineText.charAt(lineText.indexOf("...") - 1) != " ")
                        bProblem = true;
                }
                if (bProblem)
                    problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE__ROMANIZED + ". If these lines contain an ellipsis at the end of the line, it should be preceded by a space. This line ends with an ellipsis that isn't preceded by a space.");
            }
            if (!Utils_String.doesStringEndWithString(lineText, [".", "?", "!", "...", ".)", '."', "!)", '!"', "?)", '?"', ".”", "!”", "?”", "》", ":"]))
                problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE__ROMANIZED + ". These lines should usually end with either a period, a question mark or an exclamation mark, or else should end with an ellipsis. This line doesn't end with any of these things.");
            return constructFullProblemStrings(problemList);
        }

        public static function isLineThisType(lineString:String, lineStringList:Array=null, lineNum:int=-1):Boolean
        {
            // We use another, external, method to determine this at this point, so this method isn't used.
            Log.fatal("LineTypeAnalyzer_Chunk_TargetLanguage_Romanized.isLineThisType(): Method not implemented");
            return false;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Private Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        private function getToneMarkCharString(s:String):String
        {
            var result:String = "";
            for (var i:int = 0; i < s.length; i++)
            {
                if (PINYIN_LETTERS_WITH_TONE_MARKS.indexOf(s.charAt(i)) != -1)
                    result += s.charAt(i);
            }
            return result;
        }

    }
}
